package com.algento.jnitest;

import android.graphics.Bitmap;
import android.util.Log;

import java.nio.ByteBuffer;

public class Utils {
    public static byte[] bitmapToByteArray(Bitmap bitmap) {
        int bytes = bitmap.getByteCount();
        ByteBuffer buffer = ByteBuffer.allocate(bytes);
        bitmap.copyPixelsToBuffer(buffer);
        return buffer.array();
    }
    public static Bitmap byteArrayToBitmap(byte[] byteArray, int width, int heith) {
        ByteBuffer buffer = ByteBuffer.wrap(byteArray);
        Log.d("ansion", "byteArrayToBitmap: " + buffer.array().length);
        Bitmap bitmap = Bitmap.createBitmap(width, heith, Bitmap.Config.ARGB_8888);
        Log.d("ansin", "byteArrayToBitmap: " + bitmap.getByteCount());
        bitmap.copyPixelsFromBuffer(buffer);
        Log.d("ansin", "byteArrayToBitmap2: " + bitmap.getByteCount());
        return bitmap;
    }

    public native static void blurBitmap(byte[] bitmap, int radius, int unpin, int width, int height, int stride);
}
